<template>
  <view class="balance" v-if="myInfo.user_info && shenheStatus == 0">
    <view class="header">
      <view class="header-top">
        <text>{{ $t("user.my") }}</text>
        <text
          v-if="!isHidden"
          @click="clickEye(true)"
          class="iconfont icon-browse"
        ></text>
        <text
          v-else
          @click="clickEye(false)"
          class="iconfont icon-Notvisible"
        ></text>
      </view>

      <view class="header-content">
        <view @click="$utils.toUrl('/user/balance/balance-detail', 'navigate')">
          <view class="flex-y-center"
            >{{ $t("person.myBalance")
            }}<text class="iconfont icon-arrow-right"></text
          ></view>
          <view v-if="!isHidden"
            >¥<text>{{ myInfo.user_info.money | integer }}</text
            ><text style="font-size: 24rpx">{{
              myInfo.user_info.money | decimals
            }}</text></view
          >
          <view v-else>
            <text>***</text>
          </view>
        </view>
        <view
          @click="
            $utils.toUrl(
              '/integral/integral/myIntegral?integral=' +
                myInfo.user_info.integral,
              'navigate'
            )
          "
        >
          <view class="flex-y-center"
            >{{ $t("shop.integral")
            }}<text class="iconfont icon-arrow-right"></text
          ></view>
          <view v-if="!isHidden">{{ myInfo.user_info.integral }}</view>
          <view v-else>***</view>
        </view>
      </view>

      <view class="header-bottom">
        <view
          @click="$utils.toUrl('/user/my_coupon/my_coupon', 'navigate')"
          class="flex-col flex-x-center flex-y-center"
        >
          <view>{{ $t("common.coupon") }}</view>
          <view v-if="!isHidden"
            ><text style="font-size: 26rpx">{{ myInfo.coupon_num }}</text
            >{{ $t("writeOff.total") }}</view
          >
          <view v-else><text style="font-size: 26rpx">***</text></view>
        </view>
        <view
          @click="$utils.toUrl('/user/share/index', 'navigate')"
          class="flex-col flex-x-center flex-y-center"
        >
          <view>{{ $t("share.commission") }}</view>
          <view style="font-size: 26rpx" v-if="!isHidden"
            >¥{{ myInfo.user_info.price }}</view
          >
          <view style="font-size: 26rpx" v-else>***</view>
        </view>
        <view
          @click="
            $utils.toUrl('/user/write_off_card/write_off_card', 'navigate')
          "
          class="flex-col flex-x-center flex-y-center"
        >
          <view>{{ $t("user.card") }}</view>
          <view v-if="!isHidden"
            ><text style="font-size: 26rpx">{{ myInfo.verify_num }}</text
            >{{ $t("writeOff.total") }}</view
          >
          <view v-else><text style="font-size: 26rpx">***</text></view>
        </view>
      </view>
    </view>

    <view class="tab">
      <view @click="$utils.toUrl('/user/balance/balance-bonus', 'navigate')" v-if="myInfo.balance_to_commission">
        <view class="iconfont icon-CurrencyConverter"></view>
        <view>{{ $t("user.balance") }}</view>
      </view>
      <view @click="$utils.toUrl('/user/balance/recharge', 'navigate')">
        <view class="iconfont icon-creditcard"></view>
        <view>{{ $t("user.recharge") }}</view>
      </view>
      <view @click="$utils.toUrl('/integral/integralStore/index', 'navigate')">
        <view style="font-size: 58rpx" class="iconfont icon-gift"></view>
        <view>{{ $t("integral.mall") }}</view>
      </view>
      <view @click="$utils.toUrl('/user/balance/balance-detail', 'navigate')">
        <view class="iconfont icon-jiaobiao"></view>
        <view>{{ $t("user.detail") }}</view>
      </view>
    </view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from '@/components/shenhe/shenhe';
export default {
  component:{
    Shenhe,
  },
  data() {
    return {
      myInfo: {},
      isHidden: false,
    };
  },
  filters: {
    integer(data) {
      return data.substr(0, data.length - 3);
    },
    decimals(data) {
      return data.substr(data.length - 3, 3);
    },
  },
  computed: {
    hide() {
      return function (val) {
        if (this.isHidden) {
          return "***";
        } else {
          return val;
        }
      };
    },
  },
  onShow() {
    this.getMyinfo();
  },
  methods: {
    async getMyinfo() {
      try {
        const res = await this.$allrequest.request.userindex({}, true);
        if (res.code != 0) throw res;
        this.myInfo = res.data;
      } catch (error) {
        this.$utils.toast(error.msg);
      }
    },
    clickEye(b) {
      this.isHidden = b;
    },
  },
};
</script>

<style lang="scss" scoped>
.header {
  margin: 40rpx auto 0;
  background: #f0250e;
  box-shadow: 0rpx 6rpx 24rpx rgba(240, 37, 14, 0.3);
  opacity: 1;
  border-radius: 20rpx;
  color: #fff;
  .header-top {
    padding: 34rpx 30rpx 36rpx;
    line-height: 42rpx;
    font-size: 30rpx;
    font-weight: 600;
    .iconfont {
      font-size: 32rpx;
      margin-left: 10rpx;
    }
  }

  .header-content {
    margin-bottom: 30rpx;
    padding-left: 70rpx;
    display: flex;
    > view:nth-child(1) {
      flex: 1;
      > view:nth-child(2) {
        height: 66rpx;
        font-size: 24rpx;
        font-weight: 600;
        color: #ffffff;
        > text {
          font-size: 48rpx;
        }
      }
    }
    > view:nth-child(2) {
      flex: 1;
      > view:nth-child(2) {
        height: 66rpx;
        font-size: 48rpx;
        font-weight: 600;
        color: #ffffff;
      }
    }
    .icon-arrow-right {
      font-size: 22rpx;
    }
  }

  .header-bottom {
    position: relative;
    width: 100%;
    height: 108rpx;
    display: flex;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: #fff;
      opacity: 0.1;
      border-radius: 0rpx 0rpx 20rpx 20rpx;
    }
    > view {
      flex: 1;
      position: relative;
      &::before {
        content: "";
        position: absolute;
        right: 0;
        top: 50%;
        transform: translate(0, -50%);
        height: 30rpx;
        width: 2rpx;
        background: #fff;
        opacity: 0.1;
      }
      > view:nth-child(1) {
        height: 34rpx;
        font-size: 24rpx;
        opacity: 1;
      }
      > view:nth-child(2) {
        font-size: 22rpx;
        line-height: 36rpx;
      }
    }
  }
}

.tab {
  margin-top: 94rpx;
  padding: 0 30rpx;
  display: flex;
  > view {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .iconfont {
    margin-bottom: 20rpx;
    font-size: 60rpx;
  }
}
</style>
